﻿using BenCaoXuan.Infrastructure.Dto.Admin.employee;
using BenCaoXuan.Service.Interface.admin;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace BenCaoXuan.Api.Admin.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BaseController : ControllerBase
    {
        protected readonly I_Login_Service _login_Service;

        public BaseController(I_Login_Service login_Service)
        {
            _login_Service = login_Service;


            // Thread.Sleep(Config.GetRandom(1000,2000));
        }

        /// <summary>
        /// 获取当前登录管理端的用户
        /// </summary>
        /// <returns></returns>
        /// 
        protected Employee_Dto Get_AdminUser()
        {
            var code = Response.HttpContext.User.Identity?.Name;
            var actorClaim = Response.HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Actor);
            string account = actorClaim!.Value;
            var employee = _login_Service.Check_Login(code, account!);
            if (employee == null)
            {
                throw new Exception("登录已过期");
            }

            return employee;
        }




    }
}
